package cn.truistic.enmicromsg.main.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.truistic.enmicromsg.R;
import cn.truistic.enmicromsg.wx.wx_accountmanage.AccountManageActivity;
import cn.truistic.enmicromsg.adapter.MyAdapter;
import cn.truistic.enmicromsg.main.MainMVP;
import cn.truistic.enmicromsg.main.presenter.GroupPresenter;
import cn.truistic.enmicromsg.wx.wx_friendscircle.FriendsCircleActivity;
import cn.truistic.enmicromsg.wx.wx_keysendmessage.KeySendMessageActivity;
import cn.truistic.enmicromsg.wx.wx_nearby.NearbyActivity;

/**
 * 群聊管理
 */
public class GroupsFragment extends Fragment implements AdapterView.OnItemClickListener ,MainMVP.IGroupsView {

    public static final int[] icon = {R.drawable.but_sele_user, R.drawable.but_sele_user, R.drawable.but_sele_near,
            R.drawable.but_sele_user, R.drawable.but_sele_user, R.drawable.but_sele_user,
            R.drawable.but_sele_addfriend, R.drawable.but_sele_user, R.drawable.but_sele_user,
            R.drawable.but_sele_user, R.drawable.but_sele_friendcomment, R.drawable.but_sele_sendmessage,
            R.drawable.but_sele_user
    };
//    R.drawable.but_sele_user, R.drawable.but_sele_address, R.drawable.but_sele_near,
//    R.drawable.but_sele_restart, R.drawable.but_sele_autoreply, R.drawable.but_sele_phone, R.drawable.but_sele_addfriend,
//    R.drawable.but_sele_addgroup, R.drawable.but_sele_project, R.drawable.but_sele_bottle, R.drawable.but_sele_friendcomment,
//    R.drawable.but_sele_sendmessage, R.drawable.but_sele_autoreply
    public static final String[] iconName = {"暂时模拟", "暂时模拟", "附近人", "暂时模拟",
            "暂时模拟", "暂时模拟", "一键加群友", "暂时模拟", "暂时模拟", "暂时模拟", "朋友圈", "一键发消息", "暂时模拟"};
    //"操作指南", "地点管理", "附近人", "微信重置",
//            "一键开始", "通讯录", "一键加好友", "一键加群友", "公众号", "漂流瓶", "朋友圈", "一键发消息", "自动回复"

    private View mGroupView;
    private GridView mGridView ;
    private MyAdapter mSimpleAdapter ;
    private Context mContext;
    private  MainMVP.IGroupsPresenter mGroupsPresenter;


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mContext = getActivity() ;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mGroupView =  inflater.inflate(R.layout.fragment_groups, container, false);
        mGroupsPresenter = new GroupPresenter(mContext);
        initView();
        return mGroupView;
    }

    /**
     * 初始化View
     */
    private void initView() {
        mGridView = (GridView) mGroupView.findViewById(R.id.gridview);
        mSimpleAdapter = new MyAdapter(mContext ,initList());
        mGridView.setAdapter(mSimpleAdapter);
        mGridView.setOnItemClickListener(this);
    }

    /**
     * 添加数据
     * @return
     */
    public List<Map<String, Object>> initList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (int i = 0; i < icon.length; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("ItemImage", icon[i]);
            map.put("ItemText", iconName[i]);
            list.add(map);
        }
        return list;
    }

    /**
     * item 点击监听
     * @param parent
     * @param view
     * @param position
     * @param id
     */
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (position){
            case 0:
                mGroupsPresenter.startActivity(AccountManageActivity.class);//使用公告
                break;
            case 1:
                Toast.makeText(mContext, "暂未开启该功能....", Toast.LENGTH_SHORT).show();
                break;
            case 2:
                mGroupsPresenter.startActivity(NearbyActivity.class);//附近的人
                break;
            case 3:
                Toast.makeText(mContext, "暂未开启该功能....", Toast.LENGTH_SHORT).show();
                break;
            case 4:
                Toast.makeText(mContext, "暂未开启该功能....", Toast.LENGTH_SHORT).show();
                break;
            case 5:
                Toast.makeText(mContext, "暂未开启该功能....", Toast.LENGTH_SHORT).show();
                break;
            case 6:
//                Toast.makeText(mContext, "暂未开启该功能....", Toast.LENGTH_SHORT).show();
                break;
            case 7:
                Toast.makeText(mContext, "暂未开启该功能....", Toast.LENGTH_SHORT).show();
                break;
            case 8:
                Toast.makeText(mContext, "暂未开启该功能....", Toast.LENGTH_SHORT).show();
                break;
            case 9:
                Toast.makeText(mContext, "暂未开启该功能....", Toast.LENGTH_SHORT).show();
                break;
            case 10:
                mGroupsPresenter.startActivity(FriendsCircleActivity.class);  //朋友圈
                break;
            case 11:
                mGroupsPresenter.startActivity(KeySendMessageActivity.class);//附近的人
                break;
            case 12:
                Toast.makeText( mContext, "暂未开启该功能....", Toast.LENGTH_SHORT).show();
                break;
            case 13:
                Toast.makeText( mContext , "暂未开启该功能....", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
